/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 * Date:             2015.07.13                                          *
 * Description:      an implement to input database for using map type   *
 *                                                                       *
 *************************************************************************/

//declaration header
#include "COMMON/tbox/MapDatabase.h"

//COMMON headers
#include "COMMON/tbox/Utilities.h"

namespace FreeMAPs
{

MapDatabase::MapDatabase()
{}



MapDatabase::~MapDatabase()
{}



std::set<std::string>
MapDatabase::get_keys() const
{
    return Utilities::get_map_keys (d_string_string_maps);
}



bool
MapDatabase::is_string_string_map(
    const std::string& key) const
{
    return (d_string_string_maps.count (key) > 0);
}



void
MapDatabase::put_string_string_map(
    const std::string& key,
    const std::map<std::string, std::string>& data)
{
    if (d_string_string_maps.count (key) == 0)
    {
        d_string_string_maps.insert (std::make_pair (key, data));
    }
    else
    {
        for (std::map<std::string, std::string>::const_iterator pos = data.begin();
                pos != data.end(); ++pos)
        {
            d_string_string_maps[key].insert (*pos);
        }
    }
}



std::map<std::string, std::string>
MapDatabase::get_string_string_map(
    const std::string& key) const
{
    std::map<std::string, std::map <std::string, std::string> >::const_iterator find = d_string_string_maps.find (key);
    FREEMAPS_ASSERT (find != d_string_string_maps.end());

    return find->second;
}

}
